import LayoutView from '../layout/Index.vue'
/**
 * @description all模式渲染后端返回路由
 * @param constantRoutes
 * @returns {*}
 */
export function convertRouter(constantRoutes) {
  return constantRoutes.map((route) => {
    if (route.component) {
      if (route.component === 'Layout') {
        route.component = LayoutView
      } else {
        let path = route.component
        /* @vite-ignore */
        const routeComponent = () => import(`../views${path}`)
        route.component = routeComponent
      }
    }
    if (route.children && route.children.length) route.children = convertRouter(route.children)

    if (route.children && route.children.length === 0) delete route.children
    return route
  })
}
